package com.lemon.smartsafetynew.ui.adapter.electrical;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafetynew.entity.electrical.ElectricalItemVo;
import com.lemon.smartsafetynew.util.common.CommonUtil;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * Created by Andrew on 2018/3/12.
 */

public class ElectricalItemAdapter extends LemonRcvAdapter<ElectricalItemVo> {

    private RecyclerTClickListener<ElectricalItemVo> mListener;

    public ElectricalItemAdapter(@Nullable List<ElectricalItemVo> data,
                                 RecyclerTClickListener<ElectricalItemVo> mListener) {
        super(data);
        this.mListener = mListener;
    }

    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new ElectricalItem();
    }

    public class ElectricalItem implements AdapterItem<ElectricalItemVo> {

        @Bind(R.id.item_status_imageview)
        ImageView itemStatusImageview;
        @Bind(R.id.item_name_tv)
        TextView itemNameTv;
        @Bind(R.id.iv_right)
        ImageView ivRight;
        @Bind(R.id.item_layout)
        LinearLayout itemLayout;
        @Bind(R.id.view_top)
        View viewTop;
        private ElectricalItemVo data;
        private int pos;


        @Override
        public int getLayoutResId() {
            return R.layout.item_electricial_recycler_item;
        }

        @Override
        public void bindViews(View root) {
            ButterKnife.bind(this, root);
        }

        @Override
        public void setViews() {
            itemLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mListener.onItemClick(data, pos);
                }
            });
        }

        @Override
        public void handleData(ElectricalItemVo electricalItemVo, int position) {

            data = electricalItemVo;
            pos = position;
            if (position == 0) {
                viewTop.setVisibility(View.VISIBLE);
            } else {
                viewTop.setVisibility(View.GONE);
            }

            itemNameTv.setText(CommonUtil.avoidNullString(electricalItemVo.getArea()) + ":"
                    + CommonUtil.avoidNullString(electricalItemVo.getLocation()));

        }
    }
}
